package com.techfengs.test01;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

public class Test {
    public static void main (String[] args) throws ClassNotFoundException, SQLException {
        // 加载驱动
        Class.forName("org.mariadb.jdbc.Driver");
        // Class.forName("com.mysql.cj.jdbc.Driver");
        // 获取连接
        String url = "jdbc:mysql://192.168.3.99:3306/techfengs?useSSL=false&useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true";
        String username = "root";
        String password = "gg1111121";
        Connection conn = DriverManager.getConnection(url, username, password);
        // 创建会话
        Statement sta = conn.createStatement();
        // 发送SQL
        // String sql = "insert into t_book(id, name, author, price) values( "
        //               + "5," 
        //               + "'图解HTTP',"
        //               + "'上野 宣',"
        //               + "59.80"
        //               + ");";
        // String sql = "update t_book set price = 60.0 where id = 5;";
        String sql = "delete from t_book where id = 5;";
        int i = sta.executeUpdate(sql);
        // 处理结果
        if ( i > 0 ) {
            System.out.println("插入成功！");
            
        } else {
            System.out.println("插入失败！");

        }

        // 关闭资源
        sta.close();
        conn.close();
    }
}
